$(function () {

    const id = $.getUrlParam('id');

    //纵向滚动条滚动事件
    $(window).scroll(function () {
        $('.flow-and-task').css('margin-top', $(document).scrollTop());
    });

    //获取流程数据
    $.ajax({
        type: "GET",
        url: "/flowDef/getById",
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        data: {"id": id},
        success: function (data) {
            if (data.code === SUCCESS_CODE) {
                //console.log(data);

                let flowDefDto = data.payload;
                let flowDefEntity = flowDefDto.flowDefEntity;

                $('.flow-and-task #flowDefName').text(flowDefEntity.name);
                $('.flow-and-task #flowDefDes').text(flowDefEntity.des);

                let flowDefTaskEntityList = flowDefDto.flowDefTaskEntityList;
                $.each(flowDefTaskEntityList, function () {
                    let flowDefTaskEntity = this;
                    let taskType = flowDefTaskEntity.type;
                    if (taskType === 'start' || taskType === 'end') {
                        return true;//相当于continue，return false 相当于break
                    }

                    let taskNode = $('#taskTemplate [taskType="' + taskType + '"]');
                    let taskNodeClone = taskNode.clone(false);
                    taskNodeClone.find('[name="name"]').text(flowDefTaskEntity.name);
                    taskNodeClone.find('[name="des"]').text(flowDefTaskEntity.des);
                    if (taskType != 'pointTask') {
                        taskNodeClone.find('[name="assignees"]').text(flowDefTaskEntity.assigneesName);
                    }

                    $('.flow [taskType="end"]').before(taskNodeClone);
                });

            } else {
                toastr.error(data.msg);
            }
        }
    });
});

